package com.newbee.sustainability.common.vo;

import org.apache.commons.lang3.StringUtils;

import java.util.List;

public class ResponseVo<T> {
    private String code;
    private String message;
    private List<T> datas;
    private T data;

    private ResponseVo<T> instance(String code, String message, List<T> datas, T data) {
        this.setCode(code);
        this.setMessage(message);
        this.datas = (datas);
        this.setData(data);
        return this;
    }

    private ResponseVo<T> success(String code, String message, List<T> datas, T data) {
        return instance(StringUtils.isBlank(code) ? "0000" : code, StringUtils.isBlank(message) ? "操作成功" : message, datas, data);
    }

    private ResponseVo<T> error(String code, String message, List<T> datas, T data) {
        return instance(StringUtils.isBlank(code) ? "1111" : code, StringUtils.isBlank(message) ? "操作失败" : message, datas, data);
    }


    public ResponseVo<T> error(String code, String message, List<T> datas) {
        return error(code, message, datas, null);
    }

    public ResponseVo<T> error(String code, String message, T data) {
        return error(code, message, null, data);
    }

    public ResponseVo<T> error(String code, String message) {
        return error(code, message, (T) null);
    }

    public ResponseVo<T> error(String message) {
        return error(null, message);
    }

    public ResponseVo<T> success(String message, List<T> datas) {
        return success(null, message, datas, null);
    }

    public ResponseVo<T> success(String message, T data) {
        return success(null, message, null, data);
    }

    public ResponseVo<T> success(List<T> data) {
        return success(null, data);
    }

    public ResponseVo<T> success(T data) {
        return success(null, data);
    }

    public ResponseVo<T> success() {
        return success((T) null);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public List<T> getDatas() {
        return datas;
    }

    public void setDatas(List<T> datas) {
        this.datas = datas;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
